using Abp.MultiTenancy;
using Abp.Zero.EntityFramework;
using EntityFramework.DynamicFilters;
using RMM.Migrations.SeedData;
using System.Data.Entity.Migrations;

namespace RMM.Migrations
{
    internal sealed class Configuration : DbMigrationsConfiguration<RMM.EntityFramework.RMMDbContext>, IMultiTenantSeed
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
            ContextKey = "RMM";
        }

        public AbpTenantBase Tenant { get; set; }


        protected override void Seed(RMM.EntityFramework.RMMDbContext context)
        {
            context.DisableAllFilters();

            if (Tenant == null)
            {
                new InitialHostDbBuilder(context).Create();
                new DefaultTenantCreator(context).Create();
                new TenantRoleAndUserBuilder(context, 1).Create();
            }

            context.SaveChangesAsync().Wait();
        }
    }
}
